package com.heima.comment.controller.v1;

import com.heima.comment.service.ApCommentService;
import com.heima.comment.vo.CommentVo;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.comment.dtos.CommentDto;
import com.heima.model.comment.dtos.CommentLikeDto;
import com.heima.model.comment.dtos.CommentSaveDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/api/v1/comment")
public class ApCommentController {

    @Autowired
    private ApCommentService commentService;

    /**
     * 保存评论
     */
    @PostMapping("/save")
    public ResponseResult saveComment(@RequestBody @Valid CommentSaveDto dto){
        commentService.saveComment(dto);
        return ResponseResult.ok();
    }

    /**
     * 展示评论列表功能
     */
    @PostMapping("/load")
    public ResponseResult<List<CommentVo>> loadComment(@RequestBody @Valid CommentDto dto){
        List<CommentVo> list = commentService.loadComment(dto);
        return ResponseResult.ok(list);
    }

    /**
     * 评论点赞行为
     */
    @PostMapping("/like")
    public ResponseResult likeComment(@RequestBody @Valid CommentLikeDto dto){
        commentService.likeComment(dto);
        return ResponseResult.ok();
    }
}
